/**
 * 
 */
package de.kalinasch.pa.placereminder;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import de.kalinasch.pa.placereminder.database.IncidentDataSource;
import de.kalinasch.pa.placereminder.dmo.IncidentDMO;

/**
 * This class is used after a match of a saved reminder and the current position is noticed.
 * 
 * @author domenic
 *
 */
public class ActiveReminderActivity extends Activity implements OnClickListener{
	public static final String MAP_LATITUDE = "latitude";
	public static final String MAP_LONGITUDE = "longitude";
	public static final String MAP_RADIUS = "radius";
	public static final String MAP_TITLE = "title";
	public static final String MAP_DESC = "description";
		
	private int id = 0;
	private IncidentDMO loadIncident;
	private IncidentDataSource dbAdapter;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activereminder);

		id = getIntent().getIntExtra(ShowReminderDetailActivity.INCIDENT_ID, 0);
		dbAdapter = new IncidentDataSource(this);
		loadIncident = new IncidentDMO();
		loadIncident = dbAdapter.getIncident(id);

		TextView street = (TextView) findViewById(R.id.active_street);
		street.setText(loadIncident.getStreet());

		TextView town = (TextView) findViewById(R.id.active_town);
		town.setText(loadIncident.getTown());
		
		TextView radius = (TextView)findViewById(R.id.active_radius);
		radius.setText(loadIncident.getRadius() + "m");

		TextView title = (TextView) findViewById(R.id.active_title);
		title.setText(loadIncident.getTitle());

		TextView description = (TextView) findViewById(R.id.active_description);
		description.setText(loadIncident.getDescription());
		
		Button map = (Button) findViewById(R.id.active_button_map);
		map.setOnClickListener(this);

		Button delete = (Button) findViewById(R.id.active_button_delete);
		delete.setOnClickListener(this);
	}

	@Override
	public void onClick(View _button) {
		if ((_button.getId()) == R.id.active_button_map) {
			Intent intent = new Intent(_button.getContext(), ShowOnMapActivity.class);
			intent.putExtra(MAP_LATITUDE, loadIncident.getLatitude());
			intent.putExtra(MAP_LONGITUDE, loadIncident.getLongitude());
			intent.putExtra(MAP_RADIUS, loadIncident.getRadius());
			intent.putExtra(MAP_TITLE, loadIncident.getTitle());
			intent.putExtra(MAP_DESC, loadIncident.getDescription());
			startActivity(intent);
		}
		else if (_button.getId() == R.id.active_button_delete) {
			dbAdapter.deleteIncident(id);
		}
	}
}
